using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace SecurityLinkUp
{
    public class Log
    {
        public static void LogException(Exception ex)
        {
            // create a new log item
            LogEntry e = new LogEntry();
            e.Priority = 1;
            e.Severity = System.Diagnostics.TraceEventType.Error;
            e.Categories.Add("Exception");
            e.Title = ex.Message;
            e.Message = ex.ToString();
            e.MachineName = HttpContext.Current.Request.UserHostAddress;

            // send the item to the log
            Logger.Write(e);
        }

        public static void LogFailedLogin(string username)
        {
            // create a new log item
            LogEntry e = new LogEntry();
            e.Priority = 2;
            e.Severity = System.Diagnostics.TraceEventType.Information;
            e.Categories.Add("Auth");
            e.Title = "Failed login for user  '" + username + "'";
            e.MachineName = HttpContext.Current.Request.UserHostAddress;

            // send the item to the log
            Logger.Write(e);
        }

        public static void LogFailedPasswordChange(string username)
        {
            // create a new log item
            LogEntry e = new LogEntry();
            e.Priority = 2;
            e.Severity = System.Diagnostics.TraceEventType.Information;
            e.Categories.Add("Auth");
            e.Title = "Failed password change for user '" + username + "'";
            e.MachineName = HttpContext.Current.Request.UserHostAddress;

            // send the item to the log
            Logger.Write(e);
        }

        public static void LogFailedForgottenPassword(string username)
        {
            // create a new log item
            LogEntry e = new LogEntry();
            e.Priority = 2;
            e.Severity = System.Diagnostics.TraceEventType.Information;
            e.Categories.Add("Auth");
            e.Title = "Failed forgotten password funtionality for user '" + username + "'";
            e.MachineName = HttpContext.Current.Request.UserHostAddress;

            // send the item to the log
            Logger.Write(e);
        }

        public static void LogRegisteredUser(string username)
        {
            // create a new log item
            LogEntry e = new LogEntry();
            e.Priority = 3;
            e.Severity = System.Diagnostics.TraceEventType.Information;
            e.Categories.Add("Auth");
            e.Title = "User  '" + username + "' has just registered";
            e.MachineName = HttpContext.Current.Request.UserHostAddress;

            // send the item to the log
            Logger.Write(e);
        }
    }
}
